package vip.geeker.iotms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Strings;
import org.springframework.stereotype.Service;
import vip.geeker.iotms.help.Response;
import vip.geeker.iotms.persistance.mapper.DeviceInfoMapper;
import vip.geeker.iotms.persistance.mapper.DeviceTypeDataMapper;
import vip.geeker.iotms.persistance.model.DeviceInfo;
import vip.geeker.iotms.persistance.model.DeviceParams;
import vip.geeker.iotms.persistance.model.DeviceTypeData;
import vip.geeker.iotms.service.IDeviceTypeDataService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DeviceTypeDataService extends ServiceImpl<DeviceTypeDataMapper, DeviceTypeData> implements IDeviceTypeDataService {
    @Resource
    private DeviceTypeDataMapper deviceTypeDataMapper;

    @Resource
    private DeviceInfoMapper deviceInfoMapper;


    @Override
    public Response<PageInfo<DeviceTypeData>> queryPage(DeviceTypeData typeData) {
        PageHelper.startPage(typeData.getPageNo(), typeData.getPageSz());
        List<DeviceTypeData> list = deviceTypeDataMapper.queryPage(typeData);
        return new Response<>(new PageInfo<>(list));
    }

    @Override
    public Response addDeviceTypeData(DeviceTypeData typeData) {
        boolean suc = deviceTypeDataMapper.insert(typeData) == 1;
        Response response = new Response();
        response.setData(suc);
        return response;
    }

    @Override
    public Response deleteDeviceTypeData(DeviceTypeData typeData) {
        return null;
    }

    @Override
    public Response updateDeviceTypeData(DeviceTypeData typeData) {
        boolean res = deviceTypeDataMapper.updateByPrimaryKey(typeData) == 1;
        return new Response(res);
    }

    @Override
    public Response<DeviceTypeData> selectById(long id) {
        DeviceTypeData data = deviceTypeDataMapper.selectById(id);
        return new Response<>(data);
    }

    @Override
    public List<DeviceTypeData> queryTypeDataList(Integer typeId) {
        List<DeviceTypeData> list = deviceTypeDataMapper.selectByTypeId(typeId);
        return list;
    }

    @Override
    public List<String> queryGroupData() {
        return deviceTypeDataMapper.queryGroupData();
    }

    @Override
    public Response<PageInfo<DeviceInfo>> selectDeviceByData(int PageNo, int PageSize, String dataName) {

        PageHelper.startPage(PageNo,PageSize);
        List<DeviceInfo> list = deviceInfoMapper.selectDeviceByData(Strings.emptyToNull(dataName));
        return new Response<>(new PageInfo<>(list));
    }


}
